package com.xmall.order.utils;

import com.xmall.define.dict.OrderStatusEnum;
import com.xmall.define.base.ResultCode;
import com.xmall.exception.XmallException;

public class OrderStatusUtils {

    /**
     * 支付前检查
     */
    public static void beforePayCheck(Integer orderStatus) {
        if(OrderStatusEnum.WAIT_PAY.getStatus() != orderStatus) {
            if(OrderStatusEnum.CANCELED.getStatus() == orderStatus) {
                throw new XmallException(ResultCode.ORDER_ALREADY_CANCEL);
            }
            if(OrderStatusEnum.WAIT_CONSIGN.getStatus() == orderStatus) {
                throw new XmallException(ResultCode.ORDER_ALREADY_PAY);
            }
            throw new XmallException(ResultCode.ORDER_STATUS_ERROR);
        }
    }

    /**
     * 取消前检查
     */
    public static Boolean beforeCancelCheck(Integer orderStatus) {
        return OrderStatusEnum.WAIT_PAY.getStatus() == orderStatus;
    }

}
